package leetcode.code0923;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	int mod = (int) 1e9 + 7;

	public int threeSumMulti(int[] arr, int target) {
		int[] cnts = new int[101];
		cnts[arr[0]] += 1;
		long ans = 0;
		for (int i = 1; i < arr.length; i++) {
			int ni = arr[i];
			for (int j = i + 1; j < arr.length; j++) {
				int nj = arr[j];
				int diff = target - ni - nj;
				if (diff >= 0 && diff < 101) {// wa
					ans += cnts[diff];
					ans %= mod;// wa
				}
			}
			cnts[ni] += 1;
		}
		return (int) ans;
	}

	@Override
	public void debug4() {
		H.compare(20, this.threeSumMulti(H.str2array3("[1,1,2,2,3,3,4,4,5,5]"), 8));
		H.compare(12, this.threeSumMulti(H.str2array3("[1,1,2,2,2,2]"), 5));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
